# delimit ;
clear ;
set more off ;
est drop _all ;
cd "R:/personlig/fenellac/menarche_replication/analysis/" ;

global plusdir "R:/personlig/fenellac/stata_ado/plus/" ;
sysdir set PLUS $plusdir ;
adopath ++ $plusdir ;

* **************************************************************************** ;
* This code replicates Appendix B, Table 1.
*
* Paper: "Age of Marriage and Women's Political Engagement: Evidence from India"
* Authors: Fenella Carpena, Francesca Jensenius
* 
* Code by Fenella Carpena
* Last update: April 30, 2020
* **************************************************************************** ;

****************************************************************************** ;
* select the sample
****************************************************************************** ;

use "./input/eligible-women-ihds02-lhs.dta", clear ;
merge 1:1 IDHH PERSONID using "./input/eligible-women-ihds02-rhs.dta" ;
tab _merge ;
assert _merge == 3 ;
drop _merge ;

* keep only women who are married only once (i.e., have not ever remarried) ;
drop if ever_remarried == 1 ;
  
* keep only women age of menarche between 11-18 (1st-99th pctile) ; 
summ menarche_age ;
keep if menarche_age >= 11 & menarche_age <= 18 ;

* generating district identifier ;
egen dt_id = group(STATEID DISTID) ;

****************************************************************************** ;
* label variables for the output table 
****************************************************************************** ;

label var hh_size "\textit{Household Characteristics} \\ $\qquad$ Household size" ;
label var hh_exppc "$\qquad$ Monthly expenditure per capita (Rupees)" ;
label var hindu "$\qquad$ Hindu" ;
label var muslim "$\qquad$ Muslim" ;
label var sc "$\qquad$ Scheduled Caste" ;
label var st "$\qquad$ Scheduled Tribe" ;
label var obc "$\qquad$ Other Backward Class" ;

label var age "\\ \textit{Woman Demographic Characteristics} \\ $\qquad$ Age" ;
label var height_measure "$\qquad$ Height (cm)" ;
label var marriage_age "$\qquad$ Marriage age" ;
label var gauna_age "$\qquad$ Cohabitation age" ;
label var menarche_age "$\qquad$ Menarche age" ;
label var mother_yrs_educ "$\qquad$ Mother's years of education" ;
label var father_yrs_educ "$\qquad$ Father's years of education" ;

label var ever_schooled "$\qquad$ Ever attended school" ;
label var years_schooling "$\qquad$ Years education completed" ;
label var can_read_write "$\qquad$ Can read and write" ;
label var can_converse_english "$\qquad$ Can converse in English" ;

label var num_children_with_resp "$\qquad$ Number of children living with respondent" ;
label var num_children_alive "$\qquad$ Number of children still alive" ;
label var num_children_total "$\qquad$ Number of live births" ;

label var attended_panchayat "\\\textit{Woman Political Characteristics} \\ $\qquad$ Attended council meeting" ;
label var discuss_politics "$\qquad$ Discusses politics and the community with husband" ;
label var member_pol_org "$\qquad$ Participates in a political organization" ;

****************************************************************************** ;
* build table of summary statistics
****************************************************************************** ;

gen varname = "" ;
gen mean_full = "" ;
gen sd_full = "" ;
gen mean_rural = "" ;
gen sd_rural = "" ;
gen mean_urban = "" ;
gen sd_urban = "" ;

label var varname "" ;

label var mean_full "Mean" ;
label var mean_rural "Mean" ;
label var mean_urban "Mean" ;

label var sd_full "SD" ;
label var sd_rural "SD" ;
label var sd_urban "SD" ;

* variables list ;
local hhchars hh_size hh_exppc hindu muslim sc st obc ;

local womanchars age height_measure marriage_age gauna_age menarche_age 
mother_yrs_educ father_yrs_educ ever_schooled years_schooling can_read_write can_converse_english 
num_children_with_resp num_children_alive num_children_tot ; 

local polchars attended_panchayat discuss_politics member_pol_org ; 

****************************************************************************** ;
* get summary statistics
****************************************************************************** ;
local i = 1 ;

foreach var of varlist `hhchars' `womanchars' `polchars' { ;
	local vartext: variable label `var' ;
	replace varname = "`vartext'" in `i' ; 
	
	qui summ `var', detail ; 
	replace mean_full = string(r(mean), "%9.3f") in `i' ;
	replace sd_full = string(r(sd), "%9.3f") in `i' ;

	qui summ `var' if rural == 1, detail ; 
	replace mean_rural = string(r(mean), "%9.3f") in `i' ;
	replace sd_rural = string(r(sd), "%9.3f") in `i' ;

	qui summ `var' if rural == 0, detail ; 
	replace mean_urban = string(r(mean), "%9.3f") in `i' ;
	replace sd_urban = string(r(sd), "%9.3f") in `i' ;
	
	local ++i ;

} ;

keep varname mean* sd*  ;
dropmiss, obs force ;

texsave using "./output/table-summ-stats.tex",
	replace frag nofix nonames
	title("Summary Statistics") 
	marker(table-summ-stats)
	align(lrrrrrr)
	width(\linewidth)
	footnote("\small \vspace{-3ex} \textit{Notes:} Data from IHDS 2011--2012. 
		Marriage age is winsorized at bottom 1\%.
		The sample consists of women who have never remarried and have menarche age between 11$-$18 (1st$-$99th percentile).")
	headlines("\vspace{-4ex}")
	headerlines("& \multicolumn{2}{c}{Rural and Urban} & \multicolumn{2}{c}{Rural}& \multicolumn{2}{c}{Urban}\\\cmidrule(lr){2-3}\cmidrule(lr){4-5}\cmidrule(lr){6-7}&Mean&SD&Mean&SD&Mean&SD \\") ;

exit ;

